import { loginAPI } from '@/api/user'

export default {
  namespaced: true,
  state: () => {
    return {
      token: ''
    }
  },
  mutations: {
    setToken(state, token) {
      state.token = token
    },
    clearUserInfo(state) {
      // 清除Token
      state.token = ''
    }
  },
  actions: {
    async doLogin(ctx, { username, password }) {
      // 调用接口
      const res = await loginAPI({ username, password })
      // 2.提交mutation
      ctx.commit('setToken', res.data.token)
    }
  }
}



